/**
	@author yangcaho message         
**/
YOUXIXIU = window.YOUXIXIU || {};
YOUXIXIU.MAIN= YOUXIXIU.MAIN || {};
YOUXIXIU.MAIN.PoupDetail = (function($) {
	var html='';
	var status={notice:false,atme:false,unread:false}
	var notice_num,atme_num,unread_num;
	var opt={};
	var defaults={
		id:'id',
		bind_class:"poup_show_detail",
		interface_url:'/interface/pubu/json_get_item_by_id.php',//弹出详细信息
		tpl_id:'poup_detail',
		top_height:"100",
		contain_class:"",
		close_poup_class:"close_poup",
		id : 0
	};
	//-----global functions ------// 
	function chkDefault(options)
	{
		for(key in defaults)
		{
			if(typeof(options[key])=='undefined')
			{
				options[key]=defaults[key];
			}
		}
		return options;
	}

	
	function bindclose()
	{
		$("."+opt.close_poup_class).die("click");
		$("."+opt.close_poup_class).live("click",function(e){

			close_poup();
		});
		
		
	}

	function close_poup()
	{
		$("."+opt.contain_class).remove();
		$(".mask").hide();//蒙层
	}
	

	function showdetail()
	{
			$CONFIG= {};
			
			$CONFIG.top_height = $(window).scrollTop()+opt.top_height;
				
			
			$.getJSON(opt.interface_url+"?t=jsonp&id="+opt.id+"&callback=?", function(json){
			if(typeof(json)!='undefined')
			{
				$CONFIG.nick= json.data.create_nickname;
				$CONFIG.uid= json.data.create_uid;
				$CONFIG.img_src= json.data.mw_pic;
				$CONFIG.create_time= json.data.create_time;
				$CONFIG.source= json.data.source;
				$CONFIG.id= json.data.id;
				$CONFIG.content= json.data.content;
				$CONFIG.count_love= json.data.count_love;
				$CONFIG.count_reply= json.data.count_reply;
				$CONFIG.big_pic= json.data.big_pic;
				$CONFIG.count_more= json.data.count_reply -3 ;
				if($CONFIG.count_more < 0) $CONFIG.count_more=0;
				$CONFIG.list= json.data.list;

				$("."+opt.contain_class).remove();

				
				
				$(".mask").show();//蒙层

				$("#"+opt.tpl_id).tmpl($CONFIG).appendTo($("body"));
				
			}
			
			
				
		});


	}

	function bind_page_click_comment()
	{
		
		$(".comment_page_btn").die("click");
		$(".comment_page_btn").live("click",function(e){
			var id = $(e.target).attr("mid");
			var content = $(e.target).parents("div").find("textarea").val();
		
			$.getJSON("/interface/mblog/json_add_mblog_reply.php?t=jsonp&id="+id+"&content="+content+"&callback=?", function(json){
			if(typeof(json)!='undefined')
			{

				if(json.error == 1)
				{
					YOUXIXIU.MAIN.Tips.Show(json.errmsg);
				}
				else
				{
				
					YOUXIXIU.MAIN.Tips.Show(json.errmsg);
					location.reload();
					
						
				}
				

				
			}
			
			
				
		});

		
		});

		bind_add_reply();
		bind_reply_del_btn();
	}

	function bind_click_comment()
	{
		$(".comment_btn").die("click");
		$(".comment_btn").live("click",function(e){
			var id = $(e.target).attr("mid");
			var content = $(e.target).parents("div").find("textarea").val();
		
			$.getJSON("/interface/mblog/json_add_mblog_reply.php?t=jsonp&id="+id+"&content="+content+"&callback=?", function(json){
			if(typeof(json)!='undefined')
			{

				if(json.error == 1)
				{
					YOUXIXIU.MAIN.Tips.Show(json.errmsg);
				}
				else
				{
				
					
					var html = $(e.target).parents(".weibo-share-comment").find("ul").html();

					html = '<li><div class="fl"><a href="/user/?uid='+json.user_info.uid+'" target="_blank"><img src="'+json.user_info.user_pic+'"></a></div><div class="infor">       <a target="_blank" href="/user/?uid='+json.user_info.uid+'">'+json.user_info.user_nickname+'</a>：'+content+' (1秒前)       <p class="fr"><a class="reply_del_btn" value="'+json.last_insert_id+'" onclick="return false;" href="javascript:;">删除</a> <a nick="'+json.user_info.user_nickname+'" class="reply_btn" onclick="return false;" href="javascript:;">回复</a></p>      </div>     </li>' + html;
					$(e.target).parents(".weibo-share-comment").find("ul").html(html)
						
				}
				

				
			}
			
			
				
		});

		
		});


		bind_add_reply();
		bind_reply_del_btn();
	}


	function bind_add_reply()
	{
		$(".reply_btn").die("click");

		$(".reply_btn").live("click",function(e){
			
			var nick = "回复@"+ $(e.target).attr("nick")+":";

			$(e.target).parents(".weibo-share-comment").find("textarea").val(nick);
		
		});
	}

	function bind_reply_del_btn()
	{
		$(".reply_del_btn").die("click");

		$(".reply_del_btn").live("click",function(e){
			
			var id = $(e.target).attr("value");

			$.getJSON("/interface/mblog/json_add_mblog_reply.php?t=jsonp&id="+id+"&type=del&callback=?", function(json){
			if(typeof(json)!='undefined')
			{
				if(json.error == 1)
				{
					YOUXIXIU.MAIN.Tips.Show(json.errmsg);
				}
				else
				{
					$(e.target).parents("li").hide();

					YOUXIXIU.MAIN.Tips.Show(json.errmsg);
				}

				
			}
		
			});
		});
	}




	function bind_key()
	{
		$(window).keydown(function(event){
			 switch(event.keyCode) {
				case 27 : close_poup();;
		 
				}
	
		});
	
	}

	
	return {
			init: function(options)
			{
				opt=chkDefault(options);
				showdetail();
				bindclose();
				bind_key();

			},
			showdetail:function(){
				return showdetail();
			},
			bind_click_comment:function(){
				return bind_click_comment();
			},
			
			bind_page_click_comment:function(){
				return bind_page_click_comment();
			}
		};

})(jQuery);